/* marco_polo.h -- header principal da biblioteca marco_polo
 *
 * Copyright (C) 2008, Diogo F. S. Ramos <diogofsr@grad.icmc.usp.br>
 *                     Bruno Ribeiro de Oliveira
 *                     Arineiza Cristina Pinheiro
 *                     Tomas Grover <tomas.grover@usp.br>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/** @file
 *   
 * Header principal da biblioteca marco_polo.
 */

#ifndef MARCO_POLO_H_
#define MARCO_POLO_H_

#include <libplayerc/playerc.h>
#include <cv.h>

/* Defines */
#define SQUARE_MAX_INC 20
#define SQUARE_MIN_INC -SQUARE_MAX_INC
#define SQUARE_OCCUPIED SQUARE_MAX_INC/2
#define SQUARE_FREE -SQUARE_MAX_INC/2

/* Typedefs */
typedef struct marco_polo_t marco_polo_t;

/* Enums */
enum square_state
{
    UNKNOWN = 128,
    OCCUPIED = 0,
    FREE = 255
};

/** Estutura pricipal de guarda marco_polo_t s  */
struct marco_polo_t
{
    playerc_client_t *client;	/**< Client da biblioteca player */
    playerc_laser_t *laser;	/**< Laser */
    playerc_position2d_t *position2d; /**< Odômetro */
    int map_pos_x_orig;		      /**< Posição X global de início */
    int map_pos_y_orig;		      /**< Posição Y global de início */
    char * map_name;
    IplImage *map_image;
    int **map;
    int map_width;
    int map_height;
    double px;
    double py;
    double map_square_size;
};

/* marco_polo_t *****************************************************************/
void mp_init( const char *server, const char *port );
marco_polo_t * mp_new( const char *server, const int port, const char * map_name );
void mp_destroy( marco_polo_t *explorer );
void mp_draw_map( marco_polo_t * explorer );
void mp_draw_pixel(marco_polo_t * explorer, int x, int y, unsigned char r, unsigned char g, unsigned char b);
void mp_map_mark_square( marco_polo_t * explorer, int x, int y, enum square_state state);
void mp_map_image_mark_square( marco_polo_t * explorer, int x, int y, enum square_state state);
double mp_laser_to_global_rad( const double pa, const double laser );
void mp_map_x_y_obstacle( marco_polo_t * explorer, double obs_dist, double obs_angle, int *x, int *y);
void mp_map_image_update( marco_polo_t * explorer );
void mp_map_mark_open_space( marco_polo_t * explorer, int x, int y );
int mp_map_get_pos_x( marco_polo_t * explorer );
int mp_map_get_pos_y( marco_polo_t * explorer );
void mp_walk_around( marco_polo_t * explorer );
void mp_update_position( marco_polo_t * explorer );
#endif /*MARCO_POLO_H_*/
